* Drop if either acquirer or target has no products before (because guaranteed to be no overlap)
drop if nprod_before==0 | nprodT==0

egen rankA = rank(vrdA_before), by(cvrnrA aar) field
gen rankA1 = (rankA==1)
egen sumrankA1 = sum(rankA1), by(cvrnrA aar)
* Only one max
sum sumrankA1
gen double cn8plus_coreA = cn8plus if rankA==1

egen rankT = rank(vrdT_before), by(cvrnrA aar) field
gen rankT1 = (rankT==1)
egen sumrankT1 = sum(rankT1), by(cvrnrA aar)
* 2 maxes
sum sumrankT1
bysort cvrnrA aar rankT: gen dup = _n
gen double cn8plus_coreT1 = cn8plus if rankT==1 & dup==1

* Use shares besides ranks
egen sumvrdA_before = sum(vrdA_before), by(cvrnrA aar)
gen shareA_before = vrdA_before/sumvrdA_before
gen shareA_before_overlap = shareA_before if vrdA_before!=. & vrdT_before!=.

egen sumvrdT_before = sum(vrdT_before), by(cvrnrA aar)
gen shareT_before = vrdT_before/sumvrdT_before
gen shareT_before_overlap = shareT_before if vrdA_before!=. & vrdT_before!=.

gen samecore = (rankA==1 & rankT==1)
gen overlap = (vrdA_before!=. & vrdT_before!=.)

gen shareA_before_core = shareA_before if rankA==1
gen shareT_before_core = shareT_before if rankT==1

gen top2 = ((rankA==1 & rankT<=2) | (rankT==1 & rankA<=2))
gen above10 = (shareA_before>0.1 & shareA_before!=. & shareT_before>0.1 & shareT_before!=.)

collapse (max) samecore overlap top2 above10 (sum) nsp_before = overlap shareA_before_overlap shareT_before_overlap (mean) nprod_before nprodT nprod_after shareA_before_core shareT_before_core, by(cvrnrA aar)

*Double check same
* Ratio of same pre-merger products to unique number of products of acquirer + target before merger (i.e., overlap from combined's perspective)
gen share_nsp_before = nsp_before/(nprod_before + nprodT - nsp_before) if nprod_before>0 & nprodT>0
sum share_nsp_before

* Fact 2
*cn8plus within 4-digit sector
*tab samecore
*tab top2
*tab overlap

sum samecore
post stats ("Fact 2") ("") ("Same core") (r(N)) (r(mean)) (r(sd))

sum top2
post stats ("Fact 2") ("") ("Same top 2") (r(N)) (r(mean)) (r(sd))

sum overlap
post stats ("Fact 2") ("") ("Overlap") (r(N)) (r(mean)) (r(sd))
